<?php
include_once "../header1.php";
?>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function showHint(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
  var sch_id=document.forms["form1"]["sch_id"].value;
  str=str+","+sch_id;
xmlhttp.open("GET","upp_tea_names.php?q="+str,true);
xmlhttp.send();
}
function fill(val)
{
document.form1.TeaName.value=val;
document.getElementById("List").innerHTML="";
}
</script>
<script type="text/javascript">
function showSchool(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
  var sch_id=document.forms["form1"]["sch_id"].value;
  str=str+","+sch_id;
xmlhttp.open("GET","upp_sch_names.php?q="+str,true);
xmlhttp.send();
}
function fills_n(val)
{
document.Upp_res.School_Id.value=val;
document.getElementById("List").innerHTML="";
}
</script>
<link rel="stylesheet" href="../css/datepicker.css" type="text/css" />
    <link rel="stylesheet" media="screen" type="text/css" href="../css/layout.css" />
  	<script type="text/javascript" src="../js/jquery.js"></script>
	<script type="text/javascript" src="../js/datepicker.js"></script>
    <script type="text/javascript" src="../js/eye.js"></script>
    <script type="text/javascript" src="../js/utils.js"></script>
    <script type="text/javascript" src="../js/layout.js?ver=1.0.2"></script>
</head>
<body>
<?php
include_once ("../Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("../index.php");
}
   
   else
   {
   if(isset($_POST['SaveChanges']))
	   {
$TeaName=$_POST['TeaName'];
$name=explode(" ",$TeaName);
$fn=$name[0];
$ln=$name[1];
$results= mysql_query("SELECT * FROM teacher Where First_Name='$fn' AND Last_Name='$ln'");
if($row = mysql_fetch_array($results))
{
 $T_NIC_Number=$row['T_NIC_Number'];
}
if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $getteSch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
   if($rowsc=mysql_fetch_array($getteSch))
   {
   $School_Idte=$rowsc['School_Id'];
    if($Own_School_Id==$School_Idte)
   {
   require_once 'upp.php';
    }
    else
	   {
	   $_SESSION['errornorow']="Sorry you are not allowed to do this!";
	   }
   }
   }
   }
   else if($_SESSION['Access_Type']=="Administrator")
{
require_once 'upp.php';
}   
   else
	   {
	   $_SESSION['errornorow']="Sorry you are not allowed to do this!";
	   }
}
if(isset($_POST['Edit_This']))
{
$TeaName=$_POST['TeaName'];
$name=explode(" ",$TeaName);
$fn=$name[0];
$ln=$name[1];
$results= mysql_query("SELECT * FROM teacher Where First_Name='$fn' AND Last_Name='$ln'");
if($row = mysql_fetch_array($results))
{
 $T_NIC_Number=$row['T_NIC_Number'];
}
$_SESSION['$T_NIC_Number']=$T_NIC_Number;
 if($TeaName=="")
{
	$_SESSION['errornorow']="Please select the Teacher's name!";
}
else
{
if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $getteSch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
   if($rowsc=mysql_fetch_array($getteSch))
   {
   $School_Idte=$rowsc['School_Id'];  
   if($Own_School_Id==$School_Idte)
   {
   $result=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
if(mysql_num_rows($result)==0)
{
 $_SESSION['errornorow']="Very sorry there is no result!";
}
   }
    else
	   {
	   $_SESSION['errornorow']="Sorry you are not allowed to do this!";
	   }
   }
   
   }
    else
	   {
	   $_SESSION['errornorow']="Sorry you are not allowed to do this!";
	   }
   }
     else if($_SESSION['Access_Type']=="Administrator")
{
 $result=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
if(mysql_num_rows($result)==0)
{
 $_SESSION['errornorow']="Very sorry there is no result!";
}
}
 else
	   {
	   $_SESSION['errornorow']="Sorry you are not allowed to do this!";
	   }
}
	   }
   ?>
   <?php

include_once "../header2.php";


?>
<?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
 <div id="lefttablereg"><form action="#" method="POST" name="form1">
  <table width="403" border="0" class="tablefontv">
    <tr>
      <td colspan="3"  scope="row" class="err"><?php
		if(isset($_POST['Edit_This'])||isset($_POST['SaveChanges']))
{
if(isset($_SESSION['errorempt']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo ($_SESSION['errorempt']).'<br/>';
		unset($_SESSION['errorempt']);
	}
	if(isset($_SESSION['error']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo ($_SESSION['error']);
		unset($_SESSION['error']);
	}
	if(isset($_SESSION['errorin']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo ($_SESSION['errorin']);
		unset($_SESSION['errorin']);
	}
if(isset($_SESSION['errordeg']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errordeg'];
unset($_SESSION['errordeg']);
}
if(isset($_SESSION['errornorow']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
}
		?></td>
      </tr>
    <tr>
      <th width="147" bgcolor="#6AB5FF"  scope="row" >Teacher's Name:</th>
      <td width="129" bgcolor="#999999">
         <?php
 $hin=$_SESSION['NIC_Number'].",".$_SESSION['Access_Type'];
		   echo "<input type='hidden' size='1' id='sch_id' name='sch_id' value='$hin'/>";
	  if(!isset($TeaName))
	{
	  $tnam=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
	  if($rot=mysql_fetch_array($tnam))
	  {
	  $TeaName=$rot['First_Name']." ".$rot['Last_Name'];
	  }
	  }	
	  echo "<input type='text' id='TeaName' name='TeaName' onKeyUp='showHint(this.value)' value='$TeaName' onClick='cleartbox()' size='35'/>";
	  ?></td>
      <td width="78" bgcolor="#6AB5FF">&nbsp;</td>
    </tr>
    <tr>
      <th colspan="3" bgcolor="#6AB5FF" scope="row" ><br/>
        <a href="updatetea.php" class="reset">Reset</a>|
        <input name="Edit_This" align="middle" type="submit" value="Edit this" class="buttonok"/></th>
      </tr>
  </table>
  <br/>
</form>
<form action="#" method="POST" name="Upp_res">
    <?php 
  if(isset($_POST['Edit_This']))
	   {
$TeaName=$_POST['TeaName'];
$name=explode(" ",$TeaName);
$fn=$name[0];
$ln=$name[1];
$results= mysql_query("SELECT * FROM teacher Where First_Name='$fn' AND Last_Name='$ln'");
if($row = mysql_fetch_array($results))
{
 $T_NIC_Number=$row['T_NIC_Number'];
}
if($TeaName!="")
	   {
	   if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $getteSch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
   if($rowsc=mysql_fetch_array($getteSch))
   {
   $School_Idte=$rowsc['School_Id'];
  
   if($Own_School_Id==$School_Idte)
   {
     $result=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
   }
   }
   }
   }
  else if($_SESSION['Access_Type']=="Administrator")
{
   $result=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
   }
   if(($result))
   {   
 if(mysql_num_rows($result)!=0)
	 { 
  echo '<table class="tablefontv">';
	if($row=mysql_fetch_array($result))
  { 
  $Role=$row['Role'];
  $T_NIC_Number=$row['T_NIC_Number'];
  $School_Id=$row['School_Id'];
  $First_Name=$row['First_Name'];
  $Last_Name=$row['Last_Name'];
  $Date_Of_Birth=$row['Date_Of_Birth'];
  $Gender=$row['Gender'];
  $Nature_Of_Appointment=$row['Nature_Of_Appointment'];
  $Service=$row['Service'];
  $Academic_Qualifications=$row['Academic_Qualifications'];
  $Professional_Qualifications=$row['Professional_Qualifications'];
  $Achievements=$row['Achievements_Awards'];
  $Address=$row['Address'];
  $Mobile_Tp_Number=$row['Mobile_Tp_Number'];
  $Home_Tp_Number=$row['Home_Tp_Number'];
  $Office_Tp_Number=$row['Office_Tp_Number'];
  $Appointment_Date=$row['Appointment_Date'];
  $Appointed_Subject=$row['Appointed_Subject']; 
  $Specialised_In=$row['Specialised_In'];
  $Spec_In=mysql_query("SELECT DISTINCT(Specialised_In) FROM teacher");	  
  while($rowsp=mysql_fetch_array($Spec_In))
  {
$Spe_In=$rowsp['Specialised_In'];
$splited_spe_In=explode(",",$Spe_In);
$All_Specia_In=explode(",",$Specia_In);
for($sp=0;$sp<count($splited_spe_In);$sp++)
{
$s_exists="";
for($spa=0;$spa<count($All_Specia_In);$spa++)
{
if($splited_spe_In[$sp]==$All_Specia_In[$spa])
{
$s_exists="yes";
break;
}
}
if($s_exists=="")
{
if(empty($Specia_In))
{
 $Specia_In=$splited_spe_In[$sp];
}
else
{
 $Specia_In=$Specia_In.",".$splited_spe_In[$sp];
}
}
}
}
	$allSpecia_In=explode(",",$Specia_In);
	$regSpecia_In=explode(",",$Specialised_In);
 echo '	<tr>';
echo '<td width="94">';
echo "Nic Number:";
echo '</td>';
echo '<td>';
echo "<input type='text' name='T_NIC_Number' value='$T_NIC_Number'>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="94">';
echo "School Id:";
echo '</td>';
echo '<td>';
$sch_name=mysql_query("SELECT * FROM school WHERE School_Id='$School_Id'");
if($sn=mysql_fetch_array($sch_name))
{
$School_Name=$sn['Name'];
}
echo "<input type='text' name='School_Id' id='School_Id' value='$School_Name' onKeyUp='showSchool(this.value)' size='35'>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="94">';
echo "Role:";
echo '</td>';
echo '<td>';
echo "<input type='text' name='Role' value='$Role'>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="94">';
echo "First Name:";
echo '</td>';
echo '<td>';
echo "<input type='text' name='First_Name' value='$First_Name'>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="130">';
echo "Last Name:";
echo '</td>';
echo '<td>';
echo "<input type='text' name='Last_Name' value='$Last_Name'>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="158">';
echo 'Date of Birth:';
echo '</td>';
echo '<td>';
echo "<input type='text' name='Date_Of_Birth' value='$Date_Of_Birth' class='inputDate' id='inputDate'>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="158">';
echo 'Gender:';
echo '</td>';
echo '<td>';
echo "<input type='text' name='Gender' value='$Gender'>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="137">';
echo 'Nature of Appointment:';
echo '</td>';
echo '<td>';
echo "<input type='text' name='Nature_Of_Appointment' value='$Nature_Of_Appointment'>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="93">';
echo 'Service:';
echo '</td>';
echo '<td>';
echo "<input type='text' name='Service' value='$Service'>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="159">';
echo 'Acadamic Qualifications:';
echo '</td>';
echo '<td>';
if($Academic_Qualifications!="")
	  {
	 $acQua= explode(",",$Academic_Qualifications);
	 $ol="";
	 $al="";
	 $oac="";
	
for($i=0;$i<count($acQua);$i++)
{
if($acQua[$i]=='O/Level')
{
$ol="yes";
echo "<input type='checkbox' name='Academic_Qualifications[]' value='O/Level' checked='checked'/>";
  echo "O/Level";
   echo '<br/>';
  }   
  if($acQua[$i]=='A/Level')
  {$al="yes";
  echo "<input type='checkbox' name='Academic_Qualifications[]' value='A/Level' checked='checked'/>";
 echo "A/Level";
  echo '<br/>';
 }
 if($acQua[$i]!='O/Level'&&$acQua[$i]!='A/Level'&&$acQua[$i]!="")
  {
  $oac="yes";
    $ac=substr($acQua[$i],4);
	echo "<input type='checkbox' name='Academic_Qualifications[]' value='Degree_holder' checked='checked'/>";
echo "Degree holder,Subjects:";
echo '<br/>';
?>
<textarea name='Academic_Qualifications_Deg'><?php echo $ac." "; ?></textarea>
<?php
 echo '<br/>';
}
}
if($ol=="")
{
echo "<input type='checkbox' name='Academic_Qualifications[]' value='O/Level'/>";
  echo "O/Level";
  echo '<br/>';
}
if($al=="")
{
echo "<input type='checkbox' name='Academic_Qualifications[]' value='A/Level'/>";
 echo "A/Level";
   echo '<br/>';
}
if($oac=="")
{
echo "<input type='checkbox' name='Academic_Qualifications[]' value='Degree_holder'/>";
echo "Degree holder,Subjects:";
  echo '<br/>';
echo "<textarea name='Academic_Qualifications_Deg'></textarea>";
}
}
else
{
echo "<input type='checkbox' name='Academic_Qualifications[]' value='O/Level'/>";
  echo "O/Level";
  echo '<br/>';
echo "<input type='checkbox' name='Academic_Qualifications[]' value='A/Level'/>";
 echo "A/Level";
   echo '<br/>';
echo "<input type='checkbox' name='Academic_Qualifications[]' value='Degree_holder'/>";
echo "Degree holder,Subjects:";
  echo '<br/>';
echo "<textarea name='Academic_Qualifications_Deg'></textarea>";
}
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="159">';
echo 'Professional Qualifications:';
echo '</td>';
echo '<td>';
echo "<textarea name='Professional_Qualifications'>".$Professional_Qualifications."</textarea>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="159">';
echo 'Achievements:';
echo '</td>';
echo '<td>';
echo "<textarea name='Achievements_Awards'>".$Achievements."</textarea>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="159">';
echo 'Address:';
echo '</td>';
echo '<td>';
echo "<input type='text' name='Address' value='$Address'>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="159">';
echo 'Mobile Telephone Number:';
echo '</td>';
echo '<td>';
echo "<input type='text' name='Mobile_Tp_Number' value='$Mobile_Tp_Number'>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="159">';
echo 'Home Telephone Number:';
echo '</td>';
echo '<td>';
echo "<input type='text' name='Home_Tp_Number' value='$Home_Tp_Number'>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="159">';
echo 'Office Telephone Number:';
echo '</td>';
echo '<td>';
echo "<input type='text' name='Office_Tp_Number' value='$Office_Tp_Number'>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="159">';
echo 'Appointment Date:';
echo '</td>';
echo '<td>';
echo "<input type='text' name='Appointment_Date' value='$Appointment_Date' class='inputDate1' id='inputDate1'>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="159">';
echo 'Appointed Subject:';
echo '</td>';
echo '<td>';
echo "<input type='text' name='Appointed_Subject' value='$Appointed_Subject'>";
echo '</td>';
 echo '</tr>';
echo '<tr>';
echo '<td width="159">';
echo 'Specialised in:';
echo '</td>';
echo '<td>';
for($s=0;$s<count($allSpecia_In);$s++)
{	
$Spe_exists="";  
 for($i=0;$i<count($regSpecia_In);$i++)
{
if($allSpecia_In[$s]==$regSpecia_In[$i])
{
$Spe_exists="yes";
  echo "<input type='checkbox' name='Specialised_In[]' value='$allSpecia_In[$s]' checked='checked'/>";
  echo $allSpecia_In[$s].'</br>';
  }
  }
  if($Spe_exists=="")
  {
  echo "<input type='checkbox' name='Specialised_In[]' value='$allSpecia_In[$s]'/>";
  echo $allSpecia_In[$s].'</br>';
  }
  }
  echo "<font color='red'>or</font> New";
  echo "<input type='text' name='New_Specialised_In' value='$New_Specialised_In'";
echo '</td>';
 echo '</tr>';
	 }
   echo '</table>';   
   echo "<br/>";
   echo '<input name="SaveChanges" align="middle" type="submit" value="Save changes" class="buttonok"/>';
 }	  
 }
 }
 }
 ?>
   </form>
    </div>
 <div id="righttablereg">
  <div class="suggestionListsch" id="List"></div>
 </div>
</div>
</div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">TEACHERS</h2>
            </div> 
<?php
include_once "menu.php";
?>
<?php
include_once "../footer.php";
?>
<?php
}
?>
</body>
</html>